package algorithms.sorts;

import java.util.Arrays;

public class InsertSort {

    public static void main(String[] args) {
        int[] arr = {100,6, 3, 1, 8, 10, 13};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    /**
     * 直接插入排序
     */
    public static void sort(int arr[]) {
        for (int i = 1; i < arr.length; i++) {
            int insert = arr[i];
            int j = i - 1;
            while (j >= 0 && insert < arr[j]) {
                arr[j + 1] = arr[j--];
            }
            arr[j + 1] = insert;
        }
    }
}
